#include "XmlElement.h"

std::string XmlElement::Create(const char *name, const char *value, int identityLevel)
{
	std::string ret;

	std::string identity;
	for (int i = 0; i < identityLevel; i++)
		identity += "\t";

	ret = identity + "<" + name + ">\n";
	ret += identity + "\t<![CDATA[" + value + "]]>\n";
	ret += identity + "</" + name + ">\n";

	return ret;
}

std::string XmlElement::OpenTag(const char *name, int identityLevel)
{
	std::string ret;

	std::string identity;
	for (int i = 0; i < identityLevel; i++)
		identity += "\t";

	ret = identity + "<" + name + ">\n";

	return ret;
}

std::string XmlElement::OpenTagWithAttribs(const char *name, int identityLevel)
{
	std::string ret;

	std::string identity;
	for (int i = 0; i < identityLevel; i++)
		identity += "\t";

	ret = identity + "<" + name + " ";

	return ret;
}

std::string XmlElement::CloseTag(const char *name, int identityLevel)
{
	std::string ret = OpenTag(name, identityLevel);
	ret.insert(identityLevel + 1, "/");
	return ret;
}

std::string XmlElement::CreateCdata(const char *value, int identityLevel)
{
	std::string identity;
	for (int i = 0; i < identityLevel; i++)
		identity += "\t";

	std::string ret;
	ret = identity;
	ret += "<![CDATA[";
	ret += value;
	ret += "]]>\n";
	return ret;
}